package qin.com;

import sun.java2d.SurfaceDataProxy;

import java.util.ArrayList;
import java.util.List;

public class UsersDao {
    public static boolean insert(Users users){
        String sql="insert into users(name,pass)values(?,?)";
        Object[] para=new Object[]{users.getName(),users.getPass()};
        return DataConnection.request(sql, para);
    }
    public static boolean update(Users users){
        String sql="update users set name=?,pass=?  where id=?";
        Object[] para=new Object[]{users.getName(),users.getPass(),users.getId()};
        return DataConnection.request(sql, para);
    }
    public static boolean del(long id){
        String sql="update users set name=?,pass=?  where id=?";
        Object[] para=new Object[]{id};
        return DataConnection.request(sql, para);
    }
    public static List<Users> getAllData(){
        List<Users> list = new ArrayList<Users>();
        String sql="select id,name,pass from users";
        list=new DataConnection<Users>().query(Users.class, sql, null);
        return list;
    }
    public static Users getUsersById(long id){
        List<Users> list = new ArrayList<Users>();
        String sql="select id,name,pass from users where id=?";
        Object[] para=new Object[]{id};
        Users users=new Users();
        list=new DataConnection<Users>().query(Users.class, sql, para);
        if(list.size()>0){
            users.setId(list.get(0).getId());
            users.setName(list.get(0).getName());
            users.setPass(list.get(0).getPass());
        }
        return users;
    }
}